package com.pkk.penguin.frame.know.java.driven.beanleftcycle.bean;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.DisposableBean;
import org.springframework.beans.factory.InitializingBean;

/**
 * @description: 一个bean
 * @author: peikunkun
 * @create: 2020-08-04 11:17
 **/
@Slf4j
public class BeanLeftCycleBean1 implements InitializingBean, DisposableBean {

  public BeanLeftCycleBean1() {
    System.out.println(this.getClass().getSimpleName() + "【构造器】  Constructor ...");
  }

  /**
   * Invoked by a BeanFactory on destruction of a singleton.
   *
   * @throws Exception in case of shutdown errors. Exceptions will get logged but not rethrown to allow other beans to
   * release their resources too.
   */
  @Override
  public void destroy() throws Exception {
    System.out.println(this.getClass().getSimpleName() + " 【DisposableBean】 destory ...");
  }

  /**
   * Invoked by a BeanFactory after it has set all bean properties supplied (and satisfied BeanFactoryAware and
   * ApplicationContextAware).
   * <p>This method allows the bean instance to perform initialization only
   * possible when all bean properties have been set and to throw an exception in the event of misconfiguration.
   *
   * @throws Exception in the event of misconfiguration (such as failure to set an essential property) or if
   * initialization fails.
   */
  @Override
  public void afterPropertiesSet() throws Exception {
    System.out.println(this.getClass().getSimpleName() + " 【InitializingBean】 init ...");
  }
}
